package com.moji.controller.api;


import com.moji.common.base.ApiResult;
import com.moji.common.entity.MyPage;
import com.moji.entity.MjBasicInfo;
import com.moji.entity.vo.CommonBasicDTO;
import com.moji.service.MjBasicInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 网站底部基本信息表(MjBasicInfo)表控制层
 *
 * @author makejava
 * @since 2024-07-21 14:35:51
 */
@RestController
@RequestMapping("api/mjBasicInfo")
@Api(tags = "基础信息相关api接口", value = "基础信息相关api接口")
public class MjBasicInfoController {
    /**
     * 服务对象
     */
    @Resource
    private MjBasicInfoService mjBasicInfoService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @PostMapping("/queryByPage")
    @ApiOperation(value = "全部网站基本信息 - 分页查询(只需要传入分页参数)", response = MyPage.class)
    public ApiResult<MyPage<MjBasicInfo>> queryByPage(@RequestBody CommonBasicDTO commonBasicDTO) {
        MyPage<MjBasicInfo> mjBannerMyPage = mjBasicInfoService.queryByPage(commonBasicDTO);
        return ApiResult.ok(mjBannerMyPage);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/detail")
    @ApiOperation(value = "根据id查看基础信息详情",response = MjBasicInfo.class)
    public ApiResult<MjBasicInfo> queryById(@RequestParam("id") Long id) {
        return ApiResult.ok(this.mjBasicInfoService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param mjBasicInfo 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "增加网站基本信息",response = MjBasicInfo.class)
    public ApiResult<MjBasicInfo> add(@Validated @RequestBody MjBasicInfo mjBasicInfo) {
        return ApiResult.ok(this.mjBasicInfoService.insert(mjBasicInfo));
    }

    /**
     * 编辑数据
     *
     * @param mjBasicInfo 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    @ApiOperation(value = "修改网站基本信息",response = MjBasicInfo.class)
    public ApiResult<MjBasicInfo> edit(@Validated @RequestBody MjBasicInfo mjBasicInfo) {
        return ApiResult.ok(this.mjBasicInfoService.update(mjBasicInfo));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除网站基本信息",response = Boolean.class)
    public ApiResult<Boolean> deleteById(@RequestParam("id")Long id) {
        return ApiResult.ok(this.mjBasicInfoService.deleteById(id));
    }

}

